package com.desmart.renjiao.main.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.desmart.renjiao.R;
import com.desmart.renjiao.main.bean.HomeIcons;

import java.util.List;

public class HomeIconAdapter extends BaseQuickAdapter<HomeIcons.Icon,HomeIconAdapter.IconViewHolder>{

    public HomeIconAdapter(@Nullable List data) {
        super(R.layout.list_item_home_icon, data);
    }

    @Override
    protected void convert(IconViewHolder helper, HomeIcons.Icon item) {
        helper.img.setImageResource(item.getImg());
        helper.tvName.setText(mContext.getString(item.getTitle()));
        String unRead = item.getUnRead();
        if (TextUtils.isEmpty(unRead)){
            helper.tvUnread.setVisibility(View.GONE);
        }else{
            helper.tvUnread.setText(unRead);
        }
    }

    class IconViewHolder extends BaseViewHolder{

        private final ImageView img;
        private final TextView tvName;
        private final TextView tvUnread;

        public IconViewHolder(View view) {
            super(view);
            img = view.findViewById(R.id.image);
            tvName = view.findViewById(R.id.tv_name);
            tvUnread = view.findViewById(R.id.tv_unread);
        }
    }

}
